package com.xq.jltx.utils;

import android.content.Context;
import android.provider.Settings;
import android.telephony.TelephonyManager;

import java.util.UUID;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2016/07/13.
 */
public class Utils {
    /**
     * 获取手机IMEI号
     * @param context
     * @return
     */
    public static String getIMEI(Context context) {
        return ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
    }

    /**
     * 获取设备id
     * @param context
     * @return
     */
    public static String getAndroidId(Context context) {
        return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    }

    /**
     * 获取手机串码
     * @param context
     * @return
     */
    public static String getSimSerialNumber(Context context) {
        return ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getSimSerialNumber();
    }

    /**
     * 获取一个能唯一标识每台Android设备的序号与服务器通信
     * @param context
     * @return
     */
    public static  String getUniqueId(Context context){

        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        String imei=tm.getDeviceId();

        String simSerialNumber=tm.getSimSerialNumber();

        String androidId =android.provider.Settings.Secure.getString(

                context.getContentResolver(),android.provider.Settings.Secure.ANDROID_ID);

        UUID deviceUuid = new UUID(androidId.hashCode(), ((long)imei.hashCode() << 32) |simSerialNumber.hashCode());

        String uniqueId= deviceUuid.toString();

        return uniqueId;

    }
}
